package com.example.ctcdemo.controller;

import com.example.ctcdemo.annotation.NeedToken;
import com.example.ctcdemo.entity.Result;
import com.example.ctcdemo.entity.ResultUtil;
import com.example.ctcdemo.utils.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description /
 * @Auther chongling guo
 * @Date 2021-07-24 10:53
 **/
@RestController
@RequestMapping("api")
public class TestController {

    @NeedToken
    @GetMapping("/getMessage")
    public Result getMessage(){
        return ResultUtil.success("yes jwt!", "通过权限");
    }

    @GetMapping("/getMessageT")
    public Result getMessageT(){
        return ResultUtil.success("yes jwt too!", "通过无权限");
    }

    @GetMapping("/getMessageS")
    public Result getMessageS(){
        Map<String, String> map = new HashMap<>();
        map.put("userId", "101");
        String token = JwtUtil.getToken(map);
        return ResultUtil.success(token, "返回令牌");
    }
}
